
#include "base_malloclib.h"

#define TCACHE_CACHE_SIZE	(2UL * 1024 * 1024)
#ifdef HDEF_CPU_MODEL_SM8350
	static const size_t tcache_maptable[HDEF_NATIVE_CPU_NR] = { 0.85 * TCACHE_CACHE_SIZE, 0.85 * TCACHE_CACHE_SIZE, 0.85 * TCACHE_CACHE_SIZE, 0.85 * TCACHE_CACHE_SIZE,
	1.1 * TCACHE_CACHE_SIZE, 1.1 * TCACHE_CACHE_SIZE , 1.1 * TCACHE_CACHE_SIZE , 1.3 * TCACHE_CACHE_SIZE};
	#define TCACHE_SIZEMAPTBL(coreid)	(tcache_maptable[coreid])
#endif

/* 引入brkheap */
#include <metalc/mlos/mmapheap.h>
DEF_MMAPHEAP_MLAYER(mmapheap_normal, BIT(21), SIZE_1G, SIZE_64G, 0, 0)

#define BINBUDDY_APDS	flat
/* 定义buddy */
#include <metalc/mlayer/binbuddy.h>
static buddy_obj_t *pbd;
/* 必须管理到 48 */
DEF_BUDDYEXT_MLAYER(buddy_ext, pbd, 16, HDEF_PTR_BITS, 21, page_alloc)

// DEF_BUDDYEXT_MLAYER(buddy_ext, pbd, 16, 21, page_alloc)


#define SLAB_APDS	apdspspin

#include <metalc/mlayer/slab_lk.h>


DEF_CLS_TC(tc, 3, 15)
/* 最小16字节才能实现 */
DEF_SLAB_MLAYER(slab, 3, 15, tc, BIT(17), 0, mlcc_palloc)


/* 定义tcache */
#include <metalc/mlayer/tcache.h>
/* 按上面对齐 */
DEF_TCACHE_MLAYER(tcache, 3, 15, tc, SIZE_4M, SIZE_2M, 2, mlcc_palloc)

#include <metalc/mladt/delayed.h>
DEF_DELAYED_MLAYER(delayed_normal, 64 * 1024, mlcc_palloc, output)


/* 组合 */
// COMPOSE_MLAYER(malloc_slab, mallocapi, tcache, slab, mmapheap_normal)
COMPOSE_MLAYER(malloc_slab_d, mallocapi, delayed_normal, tcache, slab, buddy_ext, mmapheap_normal)
// COMPOSE_MLAYER(malloc_slab_d, mallocapi, slab, buddy_ext, mmapheap_normal)

/* 定义tls */
DEF_MTLS_PTHREAD(GET_MLAYER_OBJNR(malloc_slab_d), 4096, mlcc_palloc, mp_coreid)


/* mlcc和mtls一定要放在第一位初始化 */
DEF_SYSINIT(malloc_perm_pool, malloc_slab_d, mtls)
DEF_CFLOWFIN(mtls)
DEF_CFLOWINIT(mtls, malloc_slab_d)
DEF_SYSFIN(__omega)